import React from 'react';
import { Button, Modal, Form, Input, Radio } from 'antd';
import { injectIntl } from 'react-intl';

const FormItem = Form.Item;
const createForm = Form.create;

class discount extends React.Component {

    // validatePhone=(rule, value, callback)=>{
    //     let myreg=/^1[3|4|5|7|8][0-9]{9}$/;
    //     if (value&&!myreg.test(value)) {
    //         callback('请输入正确手机号');
    //     } else {
    //         callback();
    //     }
    // }
    validateDis=(rule, value, callback)=>{
        const common = this.props.intl.messages.common;
        let reg=/^[0-9]*$/;
        if(!reg.test(value)){
            callback(common.PleaseEnterNumber);
        }else if (value>100) {
            callback(common.PleaseEnterValLess100);
        }else if (value<0) {
            callback(common.PleaseEnterValMore0);
        }else {
            callback();
        }
    }
    render() {
        const { visible, onCancel,onCreate, form } = this.props;
        const { getFieldDecorator } = form;
        const common = this.props.intl.messages.common;

        return (
            <Modal
                visible={visible}
                title={common.modifyInfo}
                okText={common.sure}
                onCancel={onCancel}
                onOk={onCreate}
            >
                <Form layout="vertical">
                    <FormItem label={`${common.loginAccount}: `}>
                        {getFieldDecorator('account', {
                            initialValue:this.props.account.account,
                            validateTrigger:'onBlur'
                        })(
                            <Input disabled/>
                        )}
                    </FormItem>
                    <FormItem label={`${common.serviceChargeDiscount}：`}>
                        {getFieldDecorator('serviceDiscount',{
                            rules: [
                                { required: true, message: common.pleaseServiceChargeDiscount },
                                {validator: this.validateDis}
                                ],
                            initialValue:this.props.account.serviceDiscount,
                            validateTrigger:'onBlur'
                        })(
                            <Input placeholder={common.percentageFrom0to100}/>
                        )}
                    </FormItem>
                    <FormItem label={`${common.rechargeDiscount}: `}>
                        {getFieldDecorator('electricDiscount',
                            {
                                rules: [
                                    { required: true, message: common.pleaseEnterRechargeDiscount },
                                    {validator: this.validateDis}
                                ],
                                initialValue:this.props.account.electricDiscount,
                                validateTrigger:'onBlur'
                            })(
                            <Input placeholder={common.percentageFrom0to100} />
                        )}
                    </FormItem>
                </Form>
            </Modal>
        );
    }
}

discount=createForm()(discount);
export default injectIntl(discount);